home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 March / PCWorld_2007-03_cd.bin / domacnost a kancelar / scribus / scribus-1.3.3.7-win32-install.exe / share / samples / Calender.py < prev    next >
Text File  |  2005-06-08  |  2KB  |  76 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """ This Script creates a Calendar Sheet for the Current Month """
  5.  
  6. import sys
  7.  
  8. try:
  9.     from scribus import *
  10. except ImportError:
  11.     print "This script only runs from within Scribus."
  12.     sys.exit(1)
  13.  
  14. import calendar
  15. import time
  16.  
  17. def main():
  18.     Month = time.localtime()[1]
  19.     Year = time.localtime()[0]
  20.     Objects = []
  21.     MonthList = ["January","February","March","April","May","June","July","August","September","October","November","December"]
  22.     DaysList = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
  23.     Xcoor = 10
  24.     Ycoor = 30
  25.     DayC = 0
  26.     Calend = calendar.monthcalendar(Year, Month)
  27.     ob = createText(10, 10, 245, 20)
  28.     Title = MonthList[Month-1] + " " + str(Year)
  29.     setText(Title, ob)
  30.     Objects.append(ob)
  31.     for lx in range(45, 245, 35):
  32.         ob = createLine(lx, 30, lx, 20*len(Calend)+50)
  33.         Objects.append(ob)
  34.     for ly in range(50, 20*len(Calend)+50, 20):
  35.         ob = createLine(10, ly, 255, ly)
  36.         Objects.append(ob)
  37.     ob = createRect(10, 30, 245, 20*len(Calend)+20)
  38.     setFillColor("None", ob)
  39.     Objects.append(ob)
  40.     for day in range(7):
  41.         ob = createText(Xcoor, Ycoor, 35, 20)
  42.         setTextAlignment(ALIGN_CENTERED, ob)
  43.         setFontSize(12, ob)
  44.         if day == 6:
  45.             setTextColor("Red", ob)
  46.         setText(DaysList[day], ob)
  47.         Objects.append(ob)
  48.         Xcoor = Xcoor + 35
  49.     Ycoor = Ycoor + 20
  50.     for lines in Calend:
  51.         Xcoor = 10
  52.         DayC = 0
  53.         for rows in lines:
  54.             if rows != 0:
  55.                 ob = createText(Xcoor, Ycoor, 35, 20)
  56.                 setTextAlignment(ALIGN_CENTERED, ob)
  57.                 if DayC == 6:
  58.                     setTextColor("Red", ob)
  59.                 setText(str(rows), ob)
  60.                 Objects.append(ob)
  61.             Xcoor = Xcoor + 35
  62.             DayC = DayC + 1
  63.         Ycoor = Ycoor + 20
  64.     groupObjects(Objects)
  65.  
  66. if __name__ == '__main__':
  67.     if haveDoc():
  68.         try:
  69.             setRedraw(False)
  70.             main()
  71.         finally:
  72.             setRedraw(True)
  73.             redrawAll()
  74.     else:
  75.         messageBox("Calendar Script", "Please run this script with a document open.", ICON_INFORMATION);
  76.